function mySudoku() {
    let startTime = new Date();
    let obj = window.document.getElementsByClassName('sudoku')[0];
    obj.style.width = 9 * 31 + 1 + 'px';
    obj.style.height = 9 * 31 + 1 + 'px';
    var xNum = [], yNum = [], gNum = [], xyL = [], xyR = [];
    var save = [];
    var ii = 8;
    for (var i = 0; i < 9; i++) {
        xNum.push([]);
        yNum.push([]);
        gNum.push([]);
        xyL.push(i + 1);
        xyR.push(i + 1);
        ii--;
        for (var j = 0; j < 9; j++) {
            var d = document.createElement('div');
            d.style.top = i * 31 + 'px';
            d.style.left = j * 31 + 'px';
            d.className = 'number';

            d.style.width = '30px';
            d.style.height = '30px';
            d.style.border = '1px solid black';
            d.style.textAlign = 'center';
            d.style.lineHeight = '30px';
            d.style.position = 'absolute';
            if (i < 3) {
                d.g = ifG(j, 0);
            } else if (i < 6) {
                d.g = ifG(j, 3);
            } else if (i < 9) {
                d.g = ifG(j, 6);
            }
            if (i == j) {
                d.l = 1;
            }
            if (ii == j - 1) {
                d.r = 1;
            }
            // $(".sudoku").append(d);
            obj.appendChild(d);
            xNum[i].push(j + 1);
            yNum[i].push(j + 1);
            gNum[i].push(j + 1);
        }
    }

    function ifG(j, i) {
        if (j < 3) {
            return i;
        } else if (j < 6) {
            return i + 1;
        } else if (j < 9) {
            return i + 2;
        }
    }

    function cUIf(num, array) {
        var t = 1;
        for (var i in array) {
            if (array[i] == num) {
                t += 1;
            }
        }
        return t;
    }

    function sPs(a, b) {
        for (var oo in a) {
            if (a[oo] == b) {
                a.splice(oo, 1);
                break;
            }
        }
    }

    function sP(n, i, j, g) {
        sPs(xNum[i], n);
        sPs(yNum[j], n);
        sPs(gNum[g], n);
    }

    function saveS(i, j) {
        var a = j - 1;
        for (var si = i; si > i - 2; si--) {
            for (var sj = a; sj > -1; sj--) {
                var sg = si * 9 + sj;
                var ss = save[sg].n;
                var sG = nS[sg].g;
                xNum[si].push(ss);
                gNum[sG].push(ss);
                yNum[sj].push(ss);
                save.splice(sg, 1);
            }
            a = 8;
        }
    }

    // var nS=$('.number');
    let nS = document.getElementsByClassName('number');
    let gun = 0;
    for (let i = 0; i < 9; i++) {
        if (gun > 1500) {
            break;
        }
        for (let j = 0; j < 9; j++) {
            var s = i * 9 + j, g = nS[s].g, cUse = [];
            for (var cu in xNum[i]) {
                var xNc = Math.floor(xNum[i][cu]);
                if (cUIf(xNc, yNum[j]) == 2 && cUIf(xNc, gNum[g]) == 2) {
                    cUse.push(xNc);
                }
            }
            if (cUse.length == 0) {
                saveS(i, j);
                i -= 2;
                gun += 1;
                break;
            } else {
                var useN = cUse[Math.floor(Math.random() * cUse.length)];
                nS[s].innerText = useN;
                sP(useN, i, j, g);
                save.push({'n': useN, 'x': j, 'y': i, 'g': g, 's': s});
            }

        }
    }
    let endTime = new Date();
    console.log("useTime:" + (endTime - startTime));
    console.log("try:"+gun);

}

export default mySudoku
